echo '---------------------------------- 部署Begin ----------------------------------'
#定义基础路径及目录
#项目部署的地址/usr/server固定，后面由项目名字加上config.prod中的端口号，根据项目
project_home=/project/expressDemo
# #jenkins服务器路径
# jenkins_home=/root/.jenkins/workspace
# #jenkins的任务名字
# project_name=text-web
# #server.js运行的依赖
# mode_modules=/usr/server/node_modules/node_modules.tar.gz
# tar -czf dist.tar.gz dist
# rm -rf dist
# if [ -d "$project_home/" ]; then
#   {
#     echo '----------------------------------文件存在----------------------------------'
#     rm -rf $project_home
#   }
# fi
# #建立新文件夹
# mkdir $project_home
# echo '---------------------------------- 文件拷贝Begin ----------------------------------'
# cp $jenkins_home/$project_name/dist.tar.gz $project_home
# cp $jenkins_home/$project_name/config.prod.js $project_home
# cp $jenkins_home/$project_name/server.js $project_home
# cp $jenkins_home/$project_name/pm2.json $project_home
# cp $mode_modules $project_home 
# echo '---------------------------------- 文件拷贝End ----------------------------------'
# echo '---------------------------------- 解压Begin ----------------------------------'
# cd $project_home
# tar -xzvf dist.tar.gz
# tar -xzvf node_modules.tar.gz
# mkdir log
# rm -rf $project_home/dist.tar.gz
# rm -rf $project_home/node_modules.tar.gz
# echo '---------------------------------- 解压End ----------------------------------'
echo '---------------------------------- Pm2Begin ----------------------------------'
#到/usr文件夹目的是因为确保pm2第一次在安全的目录运行
pm2 save
cd /usr
pm2 list
cd $project_home
pm2 startOrRestart pm2.json
echo '---------------------------------- Pm2End ----------------------------------'
echo '---------------------------------- 部署End ----------------------------------'